<template>
  <div class="prdp-outer">
    <div class="prdp-main">
      <!-- 头部标题栏 -->
      <div class="prdp-title-bar">
        <h2>模型规则设定</h2>
      </div>
      
      <!-- 主要内容区域 -->
      <div class="prdp-content-container">
        <el-row :gutter="20">
          <!-- 左上：带钢规格划分 -->
          <el-col :span="12">
            <div class="prdp-section-card">
              <h3 class="section-title">带钢规格划分</h3>
              
              <!-- 预警参数设置 -->
              <div class="subsection">
                <h4 class="subsection-title">预警参数设置</h4>
                <div class="control-row">
                  <span>钢种族选择：</span>
                  <el-select v-model="warningParams.steelGrade" placeholder="钢种族选择" style="width:200px">
                    <el-option label="显示全部" value="all" />
                    <el-option label=".TENS-0" value=".TENS-0" />
                    <el-option label=".TENS-1" value=".TENS-1" />
                    <el-option label=".TENS-2" value=".TENS-2" />
                  </el-select>
                  <el-button type="primary" @click="addSpecification" style="margin-left: 10px;">+添加规格</el-button>
                </div>
              </div>
              
              <!-- 钢种族划分规则：重新排列布局 -->
              <div class="subsection">
                <h4 class="subsection-title">钢种族划分规则</h4>
                <el-row :gutter="12">
                  <!-- 第一列：钢种族、钢牌号、操作 -->
                  <el-col :span="12">
                    <el-table :data="specificationTable" border style="width: 100%;" size="small" height="504">
                      <el-table-column prop="steelGrade" label="钢种族" min-width="80" />
                      <el-table-column prop="steelGradeNo" label="钢牌号" min-width="100" />
                      <el-table-column label="操作" min-width="60">
                        <template #default="scope">
                          <el-button type="danger" size="small" @click="deleteSpecification(scope.row)">删除</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-col>
                  <!-- 第二列：钢种族、钢质 -->
                  <el-col :span="12">
                    <el-table :data="steelGradeRules" border style="width: 100%;" size="small" height="252">
                      <el-table-column prop="steelGrade" label="钢种族" min-width="80" />
                      <el-table-column prop="steelQuality" label="钢质" min-width="100" />
                    </el-table>
                    
                    <!-- 厚度分档与宽度分档列表 -->
                    <el-table :data="thicknessWidthRules" border style="width: 100%; margin-top: 12px;" size="small" height="240">
                      <el-table-column prop="thicknessBin" label="厚度分档[mm]" min-width="120" />
                      <el-table-column prop="widthBin" label="宽度分档[mm]" min-width="120" />
                    </el-table>
                  </el-col>
                </el-row>
              </div>
            </div>
          </el-col>
          
          <!-- 右上：打滑判断规则 -->
          <el-col :span="12">
            <div class="prdp-section-card">
              <h3 class="section-title">打滑判断规则</h3>
              
              <!-- 主规则表格 -->
              <div class="subsection">
                <el-table :data="slipJudgmentRules" border style="width: 100%;" size="small" height="320">
                  <el-table-column prop="name" label="名称" min-width="150" />
                  <el-table-column prop="weight" label="权值" min-width="80">
                    <template #default="scope">
                      <el-input v-model="scope.row.weight" size="small" />
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" min-width="60">
                    <template #default="scope">
                      <el-button type="primary" size="small" @click="submitSlipRules">提交</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              
              <!-- 张力自学习规则 -->
              <div class="subsection">
                <h4 class="subsection-title">张力自学习规则</h4>
                <div class="control-row">
                  <span>自学习系数:</span>
                  <el-input v-model="selfLearningCoeff" style="width: 100px; margin: 0 10px;" />
                  <el-button type="primary" @click="modifySelfLearningCoeff">修改</el-button>
                </div>
                
                <el-table :data="groupWeights" border style="width: 100%;" size="small">
                  <el-table-column prop="group" label="组别" min-width="60" />
                  <el-table-column prop="weight" label="权值" min-width="80">
                    <template #default="scope">
                      <el-input v-model="scope.row.weight" size="small" />
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" min-width="60">
                    <template #default="scope">
                      <el-button type="primary" size="small" @click="submitGroupWeights">提交</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </el-col>
        </el-row>
        
        <el-row :gutter="20" style="margin-top: 20px;">
          <!-- 左下：细辊挠曲判断规则 -->
          <el-col :span="18">
            <el-row :gutter="12">
              <!-- 第一行：卡片1和卡片2 -->
              <el-col :span="12">
                <div class="prdp-section-card fine-roll-card">
                  <h3 class="section-title">细辊挠曲判断规则</h3>
                  <div class="control-row">
                    <span>零频分量百分比(报警记录):</span>
                    <el-input v-model="fineRollRules.alarmRecord" style="width: 100px; margin: 0 10px;" />
                    <el-button type="primary" @click="modifyFineRollRule('alarmRecord')">修改</el-button>
                  </div>
                </div>
              </el-col>
              
              <el-col :span="12">
                <div class="prdp-section-card fine-roll-card">
                  <h3 class="section-title">细辊挠曲判断规则</h3>
                  <div class="control-row">
                    <span>零频分量百分比(实时报警):</span>
                    <el-input v-model="fineRollRules.realtimeAlarm" style="width: 100px; margin: 0 10px;" />
                    <el-button type="primary" @click="modifyFineRollRule('realtimeAlarm')">修改</el-button>
                  </div>
                </div>
              </el-col>
              
              <!-- 第二行：卡片3和卡片4 -->
              <el-col :span="12">
                <div class="prdp-section-card fine-roll-card">
                  <h3 class="section-title">细辊挠曲判断规则</h3>
                  <div class="control-row">
                    <span>零频分量判断阈值:</span>
                    <el-input v-model="fineRollRules.judgmentThreshold" style="width: 100px; margin: 0 10px;" />
                    <el-button type="primary" @click="modifyFineRollRule('judgmentThreshold')">修改</el-button>
                  </div>
                </div>
              </el-col>
              
              <el-col :span="12">
                <div class="prdp-section-card fine-roll-card">
                  <h3 class="section-title">停机调试开关</h3>
                  <div class="control-row">
                    <span>1开0关:</span>
                    <el-input v-model="shutdownSwitch.value" style="width: 80px; margin: 0 10px;" />
                    <el-button type="primary" @click="modifyShutdownSwitch">修改</el-button>
                  </div>
                </div>
              </el-col>
            </el-row>
          </el-col>
          
          <!-- 右下：报警说明 -->
          <el-col :span="6">
            <div class="prdp-section-card">
              <h3 class="section-title">报警说明</h3>
              <div class="legend">
                <div class="legend-item">
                  <div class="legend-color yellow"></div>
                  <span>转矩方差超过阈值报警</span>
                </div>
                <div class="legend-item">
                  <div class="legend-color green"></div>
                  <span>磨辊报警</span>
                </div>
                <div class="legend-item">
                  <div class="legend-color red"></div>
                  <span>打滑或挠曲报警</span>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue';

// 预警参数设置
const warningParams = reactive({
  steelGrade: 'all'
});

// 规格表格数据 - 确保有三列：钢种族、钢牌号、操作
const specificationTable = ref([
  { steelGrade: '.TENS-0', steelGradeNo: 'A1008EDDSIF' },
  { steelGrade: '.TENS-0', steelGradeNo: 'CESHI' },
  { steelGrade: '.TENS-0', steelGradeNo: 'ATC3' },
  { steelGrade: '.TENS-0', steelGradeNo: 'ATC1' },
  { steelGrade: '.TENS-0', steelGradeNo: 'TD3' },
  { steelGrade: '.TENS-0', steelGradeNo: 'ST17' },
  { steelGrade: '.TENS-0', steelGradeNo: 'ST16' },
  { steelGrade: '.TENS-0', steelGradeNo: 'ST15' },
  { steelGrade: '.TENS-0', steelGradeNo: 'ST14' },
  { steelGrade: '.TENS-0', steelGradeNo: 'ST13' },
  { steelGrade: '.TENS-0', steelGradeNo: 'ST12' },
  { steelGrade: '.TENS-0', steelGradeNo: 'SPOF' },
  { steelGrade: '.TENS-0', steelGradeNo: 'SPCE' },
  { steelGrade: '.TENS-0', steelGradeNo: 'SPCD' },
  { steelGrade: '.TENS-0', steelGradeNo: 'CR2' },
  { steelGrade: '.TENS-0', steelGradeNo: 'CR240IF' }
]);

// 钢种族划分规则
const steelGradeRules = ref([
  { steelGrade: '.TENS-0', steelQuality: 'IF' },
  { steelGrade: '.TENS-1', steelQuality: 'low carbon' },
  { steelGrade: '.TENS-2', steelQuality: 'HSS(TS<590Mpa)' },
  { steelGrade: '.TENS-3', steelQuality: 'HSS(TS>590Mpa)' },
  { steelGrade: '.TENS-4', steelQuality: '默认分组' }
]);

const thicknessWidthRules = ref([
  { thicknessBin: '0.3<厚度<0.4', widthBin: '1000<宽度<1100' },
  { thicknessBin: '0.4<厚度<0.5', widthBin: '1100<宽度<1200' },
  { thicknessBin: '0.5<厚度<0.6', widthBin: '1200<宽度<1300' },
  { thicknessBin: '0.6<厚度<0.7', widthBin: '1300<宽度<1400' },
  { thicknessBin: '0.7<厚度<0.8', widthBin: '1400<宽度<1500' },
  { thicknessBin: '0.8<厚度<0.9', widthBin: '1500<宽度<1600' },
  { thicknessBin: '0.9<厚度<1.0', widthBin: '1600<宽度<1700' },
  { thicknessBin: '1.0<厚度<1.1', widthBin: '1700<宽度<1800' },
  { thicknessBin: '1.1<厚度<1.2', widthBin: '1800<宽度<1900' },
  { thicknessBin: '1.2<厚度<1.3', widthBin: '1900<宽度<2000' },
  { thicknessBin: '1.3<厚度<1.4', widthBin: '宽度≥2000' }
]);

// 打滑判断规则
const slipJudgmentRules = ref([
  { name: '实际速度下降概率阈值', weight: '0.8' },
  { name: '实际与主令速差概率阈值', weight: '0.5' },
  { name: '实际与主令速差阈值', weight: '0.06' },
  { name: '主令速度斜率阈值', weight: '0.002' },
  { name: '细辊转矩方差阈值', weight: '1.11' },
  { name: '大辊子转矩方差阈值', weight: '1.5' },
  { name: '段张力控制器输出阈值', weight: '0.1' },
  { name: '与前后辊速度均值差的绝对值阈值', weight: '0.011' }
]);

// 张力自学习规则
const selfLearningCoeff = ref('0.1');

const groupWeights = ref([
  { group: '甲组', weight: '0.2' },
  { group: '乙组', weight: '0.3' },
  { group: '丙组', weight: '0.3' },
  { group: '丁组', weight: '0.2' }
]);

// 细辊挠曲判断规则
const fineRollRules = reactive({
  alarmRecord: '0.000',
  realtimeAlarm: '0.000',
  judgmentThreshold: '0.000',
  reserved: '0.000'
});

// 停机调试开关
const shutdownSwitch = reactive({
  value: '0'
});

// 方法定义
const addSpecification = () => {
  console.log('添加规格');
};

const deleteSpecification = (row: any) => {
  console.log('删除规格:', row);
};

const submitSlipRules = () => {
  console.log('提交打滑判断规则:', slipJudgmentRules.value);
};

const modifySelfLearningCoeff = () => {
  console.log('修改自学习系数:', selfLearningCoeff.value);
};

const submitGroupWeights = () => {
  console.log('提交组别权值:', groupWeights.value);
};

const modifyFineRollRule = (type: string) => {
  console.log('修改细辊规则:', type, fineRollRules[type as keyof typeof fineRollRules]);
};

const modifyShutdownSwitch = () => {
  console.log('修改停机调试开关:', shutdownSwitch.value);
};
</script>

<style scoped>
.prdp-outer {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(to top, #eaf1fb 0%, #2c69e8 100%);
  overflow: hidden;
}

.prdp-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 20px;
}

.prdp-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.prdp-title-bar h2 {
  margin: 0;
  color: #333;
}

.prdp-content-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.prdp-section-card {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  height: fit-content;
  margin-bottom: 20px;
}

.section-title {
  margin: 0 0 20px 0;
  color: #333;
  font-size: 18px;
  font-weight: bold;
  border-bottom: 2px solid #409eff;
  padding-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title.with-action {
  border-bottom: 2px solid #409eff;
}

.subsection {
  margin-bottom: 25px;
}

.subsection-title {
  margin: 0 0 15px 0;
  color: #666;
  font-size: 16px;
  font-weight: 500;
}

.subsection-title.with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control-row {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.control-row span {
  color: #333;
  margin-right: 10px;
  white-space: nowrap;
}

.link-btn {
  padding: 0;
  font-size: 14px;
}

.control-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.control-item {
  display: flex;
  align-items: center;
}

.control-item span {
  color: #333;
  margin-right: 10px;
  white-space: nowrap;
  min-width: 200px;
}

.alarm-description {
  margin-top: 20px;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-block;
}

.legend-color.yellow {
  background-color: #f0ad4e;
}

.legend-color.green {
  background-color: #5cb85c;
}

.legend-color.red {
  background-color: #f44336;
}

.legend-item span {
  color: #333;
  font-size: 14px;
}

/* 表格样式优化 */
:deep(.el-table) {
  font-size: 13px;
}

:deep(.el-table th) {
  background-color: #f5f7fa;
  color: #333;
  font-weight: bold;
}

:deep(.el-table td) {
  padding: 8px 0;
}

/* 按钮样式 */
.el-button--primary {
  background-color: #409eff;
  border-color: #409eff;
}

.el-button--primary:hover {
  background-color: #66b1ff;
  border-color: #66b1ff;
}

.el-button--danger {
  background-color: #f56c6c;
  border-color: #f56c6c;
}

.el-button--danger:hover {
  background-color: #f78989;
  border-color: #f78989;
}

/* 输入框样式 */
:deep(.el-input__inner) {
  border-color: #dcdfe6;
}

:deep(.el-input__inner:focus) {
  border-color: #409eff;
}

/* 下拉框样式 */
:deep(.el-select .el-input__inner) {
  border-color: #dcdfe6;
}

:deep(.el-select .el-input__inner:focus) {
  border-color: #409eff;
}

/* 细辊挠曲判断规则卡片样式 */
.fine-roll-card {
  margin-bottom: 12px;
  padding: 12px;
  min-height: 120px;
}

.fine-roll-card .section-title {
  margin-bottom: 12px;
  font-size: 14px;
  color: #333;
  border-bottom: 1px solid #409eff;
  padding-bottom: 5px;
}

.fine-roll-card .control-row {
  flex-wrap: wrap;
  gap: 8px;
}

.fine-roll-card .control-row span {
  font-size: 12px;
  min-width: auto;
  flex-shrink: 0;
}

.fine-roll-card .legend {
  gap: 6px;
}

.fine-roll-card .legend-item {
  gap: 6px;
}

.fine-roll-card .legend-item span {
  font-size: 12px;
}
</style>
